package com.yfp.org.controller;


import com.yfp.common.core.domain.R;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.org.domain.vo.*;
import com.yfp.org.service.DashboardService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.List;

@RestController
@RequestMapping("/dashboard")
@Tag(name = "数字大屏")
public class DashboardController extends BaseController {

    @Resource
    private DashboardService dashboardService;

    @GetMapping("/profile/basic-info")
    @Operation(summary = "用户画像分析", description = "用户画像分析")
    public R<ProfileBasicInfoVO> profileBasicInfo() {
        ProfileBasicInfoVO profileBasicInfoVO = dashboardService.profileBasicInfo();
        return R.ok(profileBasicInfoVO);
    }

    @GetMapping("/products/top-sales")
    @Operation(summary = "产品销量排行Top10", description = "产品销量排行Top10")
    public R<List<ProductsTopSalesVO>> productsTopSales() {
        List<ProductsTopSalesVO> productsTopSalesVOS = dashboardService.productsTopSales();
        return R.ok(productsTopSalesVOS);
    }

    @GetMapping("/sales/trends")
    @Operation(summary = "销售走势分析", description = "销售走势分析")
    public R<MultiSeriesDataResponse> salesTrends() {
        MultiSeriesDataResponse multiSeriesDataResponse = dashboardService.salesTrends();
        return R.ok(multiSeriesDataResponse);
    }

    @GetMapping("/devices/total-deployed")
    @Operation(summary = "累计设备投放总数", description = "累计设备投放总数")
    public R<Long> devicesTotalDeployed() {
        Long count = dashboardService.devicesTotalDeployed();
        return R.ok(count);
    }

    @GetMapping("/devices/district-deployed")
    @Operation(summary = "每个‘区’设备投放总数", description = "每个‘区’设备投放总数")
    public R<List<DevicesDistrictDeployedVO>> devicesDistrictDeployed() {
        List<DevicesDistrictDeployedVO> devicesDistrictDeployedVOS = dashboardService.devicesDistrictDeployed();
        return R.ok(devicesDistrictDeployedVOS);
    }

    @GetMapping("/sales/ranking")
    @Operation(summary = "点位销售排行", description = "点位销售排行")
    public R<List<SalesRankingVO>> salesRanking() {
        List<SalesRankingVO> salesRankingVOS = dashboardService.salesRanking();
        return R.ok(salesRankingVOS);
    }

    @GetMapping("/sales/realtime")
    @Operation(summary = "实时销售情况额", description = "实时销售情况额")
    public R<String> salesRealtime() {
        BigDecimal bigDecimal = dashboardService.salesRealtime();
        DecimalFormat decimalFormat = new DecimalFormat("#0.00");
        String formattedValue = decimalFormat.format(bigDecimal);
        return R.ok(formattedValue);
    }
}
